package com.lgc.provider01.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lgc.provider01.entity.Product;
import com.lgc.provider01.mapper.ProductMapper;
import com.lgc.provider01.service.ProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lvguangchun
 * @email lvguangchun@konka.com
 * @date 2022-09-05 14:38
 */

@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper,Product> implements ProductService {

//    private static final Map<Integer, Product> productMap;
//
//    static {
//        productMap = new HashMap<>();
//        productMap.put(productMap.size() + 1, Product.builder().id(productMap.size() + 1).name("苹果").leftNum(10).build());
//    }

    @Resource
    ProductMapper productMapper;

    @Override
    public Product getById(Integer id) {
//        return productMap.get(id);
        return productMapper.selectById(id);
    }

    @Override
    public boolean updateById(Product product) {
//        Product update = productMap.get(product.getId());
//        update.setLeftNum(product.getLeftNum());
//        productMap.put(product.getId(), update);
        productMapper.updateById(product);
        return true;
    }

    @Override
    public List<Product> list() {
//        return new ArrayList<>(productMap.values());
        return productMapper.selectList(null);
    }
}

